#include <stdio.h>
#include "atom.h"
#include "dtd.h"

main(int argc, char *argv[])
{
    atom ele;
    atom attr;
    atom *list;

    InitDTD();
    if (argc == 2) {
	ele = GetAtom(argv[1]);
	fprintf(stdout, "Element %s:\n\tChildren:", argv[1]);
	list = GetElementChildren(ele);
	while (*list) {
	    fprintf(stdout, " %s", GetAtomVal(*list++));
	}
	fprintf(stdout, "\n\tParents:");
	list = GetElementParents(ele);
	while (*list) {
	    fprintf(stdout, " %s", GetAtomVal(*list++));
	}
	fprintf(stdout, "\n\tAttributes:");
	list = GetElementAttrList(ele);
	while (*list) {
	    fprintf(stdout, " %s", GetAtomVal(*list++));
	}
	fprintf(stdout, "\n");
    }
    else if (argc == 3) {
	DTDAttribute *ap;

	ele = GetAtom(argv[1]);
	attr = GetAtom(argv[2]);
	ap = GetElementAttrInfo(ele, attr);
	if (ap == 0) {
	    fprintf(stderr, "Attribute '%s' doesn't appear in element '%s'\n",
		    argv[2],
		    argv[1]);
	    exit(1);
	}
	fprintf(stdout, "Information on attribute '%s' for element '%s':\n",
		argv[2],
		argv[1]);
	switch (ap->type) {
	    case A_REQUIRED:
		fprintf(stdout, "\tType:\tRequired\n");
		break;
	    case A_FIXED:
		fprintf(stdout, "\tType:\t\tFixed\n");
		break;
	    case A_IMPLIED:
		fprintf(stdout, "\tType:\t\tImplied\n");
		break;
	}
	if (ap->valid & AF_DATATYPE)
	    fprintf(stdout, "\tData Type:\t%s\n", GetAtomVal(ap->dataType));
	if (ap->valid & AF_LIST) {
	    int i;

	    fprintf(stdout, "\tList:\t\t ( %s ", GetAtomVal(ap->list[0]));
	    for (i = 1; i < 10; i++) {
		if (ap->list[i])
		    fprintf(stdout, "| %s ", GetAtomVal(ap->list[i]));
	    }
	    fprintf(stdout, ")\n");
	}
	if (ap->valid & AF_DEFSTRING)
	    fprintf(stdout, "\tDefault String:\t%s\n", ap->defString);
	if (ap->valid & AF_DEFATOM)
	    fprintf(stdout, "\tDefault Value:\t%s\n", GetAtomVal(ap->defAtom));
    }
    else {
	fprintf(stderr, "usage: %s elename [eleattr]\n", argv[0]);
    }
    exit(0);
}
